package com.thudojsc.canvasengine.entity;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.RectF;

public class Sprite extends Node {
	/*Texture Info*/
	protected Bitmap mBitmap = null;
	protected Rect mTextureRegion;
	protected RectF mDrawRect = new RectF();
	
	public Sprite(final Bitmap pBitmap, final float pX, final float pY,
			final float pWidth, final float pHeight) {
		super(pX, pY, pWidth, pHeight);
		
		mTextureRegion = new Rect(0, 0, pBitmap.getWidth(), pBitmap.getHeight());
		this.mBitmap = pBitmap;
	}
	
	public Sprite(final Bitmap pBitmap) {
		this(pBitmap, 0, 0);
	}
	
	public Sprite(final Bitmap pBitmap, final float pX, final float pY) {
		this(pBitmap, pX, pY, pBitmap.getWidth(), pBitmap.getHeight());
	}
	
	public void setTextureRegion(final Rect pTextureRegion) {
		this.mTextureRegion = pTextureRegion;
	}
	
	@Override
	protected void onDraw(Canvas pCanvas) {
		mDrawRect.right = mWidth;
		mDrawRect.bottom = mHeight;
		
		pCanvas.drawBitmap(mBitmap, mTextureRegion, mDrawRect, mPaint);
	}
	
	public void setBitmap(final Bitmap pBitmap) {
		this.mBitmap = pBitmap;
	}
	
}
